<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box" id="box"></div>
    <style>
        .box{
            height: 100px;
            width: 100px;

            background-color: red;

            margin: 100px;
        }
    </style>
    <script>
        var box = document.getElementById('box')
        //距离定位父级元素边缘的距离，浏览器自动在左侧加了8px的margin，在样式中设置margin0消除
        console.log(box.offsetLeft)
        console.log(box.offsetTop)
    </script>
</body>
</html>